require "Common/define"
require "Logic/Config"
require "Common/functions"

UIEquipRefine = {}
HelperFunc.SetUIEnv(UIEquipRefine)
local this = UIEquipRefine;

this.LuaBehaviour = nil;
this.transform = nil;
this.gameObject = nil;

this.bgclose = nil;
this.IconBg = nil;
this.item = nil;
this.name = nil;
this.level = nil;
this.up = nil;
this.upnum = nil;
this.slider = nil;
this.sliderNum = nil;
this.sliderNumMax = nil;
this.middle = nil;
this.attr1 = nil;
this.attr2 = nil;
this.attr3 = nil;
this.dynamicList = nil;
this.num = nil;
this.maxNum = nil;
this.btn_choose = nil;
this.btn_cancel = nil;
this.btn_refine = nil;
this.levelMax = nil;
this.iconCurrency = nil;

this.itemAllCost = nil;
this.hasInit = false;
this.itemList = {};
this.curEquipData = nil;
this.curShowHeroData = nil;
this.partID = 0;
this.itemTable = {};
this.chooseData = {};
this.itemNums = {};
this.offset = 0;
this.tabAttr = {};
this.nothingController = nil;

this.enter_flag = nil

function UIEquipRefine.Init(herodata, equipdata)
    curShowHeroData = herodata;

    if equipdata == nil then
        curEquipData = nil;
    else
        curEquipData = logicMgr.EquipManager.getEquip(equipdata.partnerId, equipdata.part, true);
    end
    local name, package = getUIName(PanelResNames.UIEquipRefine);
    panelMgr:ShowUI(name, package, this.onCreate, Config.useLocalUI);

end

function UIEquipRefine.onCreate(obj)
    gameObject = obj;
    if not hasInit then
        hasInit = true;
        bgclose = obj:GetChild("bgclose");
        btnbgClose = obj:GetChild("bgClose");
        item = obj:GetChild("EquipItem");
        name = obj:GetChild("name");
        level = obj:GetChild("level");
        levelMax = obj:GetChild("levelMax");
        up = obj:GetChild("upnumGroup");
        upnum = obj:GetChild("upnum");
        slider = obj:GetChild("Slider");
        sliderNum = obj:GetChild("sliderNum");
        sliderNumMax = obj:GetChild("sliderNumMax");
        n88 = obj:GetChild("n88");
        effect = obj:GetChild("effect_zbjl").wrapTarget

        txt_power = n88:GetChild("num1")
        tabAttr = {}
        for i = 1,4 do
            local attr = obj:GetChild("attri"..i);
            attr.visible = false
            table.insert(tabAttr, attr)
        end

        dynamicList = obj:GetChild("itemList");
        dynamicList:SetVirtual();
        iconCurrency = obj:GetChild("iconCurrency");

        nothingController = obj:GetController("nothing");
        num = obj:GetChild("useNum");
        btn_cancel = obj:GetChild("btn_cancel");
        btn_cancel.visible = true;
        btn_refine = obj:GetChild("btn_refine");
        btn_choose = obj:GetChild("btn_choose");
        btn_choose.title = getLanguage("EquipRefineBtn")
        this.btnHelp = obj:GetChild("help")
        this.addEvent();
    end
    this.oneKeySelectLevel = 0
    itemAllCost = 0
    this.initUI();
    itemNums = {}
    chooseData = {}
end

function UIEquipRefine.addEvent()
    bgclose.onClick:Add(this.onClickClose);
    btnbgClose.onClick:Add(this.onClickClose);
    btn_choose.onClick:Add(this.onClickChoose);
    btn_cancel.onClick:Add(this.onClickCancel);
    btn_refine.onClick:Add(this.onClickRefine);
    this.btnHelp.onClick:Add(this.ClickHelp)
end

function UIEquipRefine.removeEvent()
    bgclose.onClick:Clear();
    btnbgClose.onClick:Clear();
    btn_choose.onClick:Clear();
    btn_cancel.onClick:Clear();
    btn_refine.onClick:Clear();
    this.btnHelp.onClick:Clear()
end

function UIEquipRefine.LocalListenEvent()
    ListenEvent(Config.EventType.Fresh_Refine, this.refreshUI);
end

function UIEquipRefine.LocalCloseEvent()
    CloseEvent(Config.EventType.Fresh_Refine, this.refreshUI);
end

function UIEquipRefine.OnDestroy()
    hasInit = false;
    this.removeEvent();
end

function UIEquipRefine.OnEnable()
    this.LocalListenEvent();
    this.enter_flag = false
    
end

function UIEquipRefine.OnDisable()
    this.LocalCloseEvent();
end

function UIEquipRefine.initUI()
    if curEquipData ~= nil then
        partID = curEquipData["part"];

        clearChild(IconBg, true);
        this.RefreshCurEquip()
        name.text = curEquipData.name;
        txt_power.text = EquipManager.GetPower(curEquipData)

        level.text = curEquipData["curRfLevel"];
        levelMax.text = curEquipData["maxRfLevel"]
        up.visible = false;
        upnum.text = "0"
        local consumeExp = curEquipData["consumeExp"];
        local curRfLevel = curEquipData["curRfLevel"];
        local refineCfg = dataTable.getDataTableByMultiId("t_equiprefine",curEquipData.itemModelId,curRfLevel)
        local expMax = refineCfg.f_EquipRefineLevelExp
        local itemAllExp = curEquipData["exp"];
        slider.value = itemAllExp*100/expMax;
        sliderNum.text = itemAllExp.."/"..expMax;
        offset = 0
        local money = logicMgr.ItemManager.getCurrencyCountByModelId(CurrencyEnum.MONEY);
        -- num.text = getNumString(money).."/0";
        num.text = "0/" .. getNumString(money)
        this.updataEquipAttr();
        this.updataEquip();
        this.updataBtnRefineState();
    end
end

function UIEquipRefine.refreshUI()
    local old = curEquipData.curRfLevel
    curEquipData = logicMgr.EquipManager.getEquip(curEquipData.partnerId, curEquipData.part, true);
    if curEquipData.curRfLevel > old then
        Util.PlayAction(effect, "idle", false)
    end
    this.oneKeySelectLevel = 0
    this.upRefineLevel();
    this.updataEquipAttr();
    this.updataEquip();
    this.updataBtnRefineState();
    this.RefreshCurEquip()
end
function UIEquipRefine.RefreshCurEquip()
    local itemCtrl = CtrlManager.GetCtrl(PanelNames.Item);
    if itemCtrl ~= nil then
        itemCtrl.initData(item, curEquipData);
    end
end
--装备属性(基础属性，随机属性（待整理，目前没值）)
function UIEquipRefine.updataEquipAttr()
    local baseAttrData = decodeJsonStrToTabel(curEquipData["baseAttr"]);
    local attrUp = 0;
    local preAttrUp = 0;
    local modelId = curEquipData.itemModelId
    local equipCfg = dataTable.getDataTableByStringId("t_equip",modelId)
    if not equipCfg then
        logError("找不到t_equip "..curEquipData.itemId)
        return
    end
    local nextLv = curEquipData.curRfLevel + offset
    local refineCfg = dataTable.getDataTableByMultiId("t_equiprefine", modelId, curEquipData.curRfLevel)
    if not refineCfg then
        logError("找不到t_equiprefine "..modelId..",level:"..curEquipData.curRfLevel)
        return
    end
    local nextRefineCfg = dataTable.getDataTableByMultiId("t_equiprefine",modelId,nextLv)
    if not nextRefineCfg then
        logError("找不到t_equiprefine "..modelId..",level:"..nextLv)
        return
    end
    txt_power.text = EquipManager.GetPower(curEquipData)
    for k,v in pairs(baseAttrData) do
        local item = tabAttr[k]
        if item == nil then
            break
        end
        item.visible = true
        local title = item:GetChild("title")
        local attrValue = item:GetChild("num1");
        local attrImage = item:GetChild("image1");
        local attrPre = item:GetChild("pre1");
        local attrPreValue = item:GetChild("preNum1");
        attrImage.url = "ui://ICONAtlas/attr" .. k;

        local attrName = getLanguage(string.format(Config.LangAttribute,v[1]));
        local attrUp = 0
        title.text = attrName
        if not string.IsNilOrEmpty(refineCfg.f_EquipRefineAttribute) then
            attrUp = refineCfg.f_EquipRefineAttribute[k][2]
            attrValue.text = "+".. EquipManager.formatAttr(v[1],attrUp)--EquipManager.formatAttr(v[1],v[2]).. "+".. EquipManager.formatAttr(v[1],attrUp)
        else
            attrValue.text = "--"--EquipManager.formatAttr(v[1],v[2])
        end
        if offset > 0 then
            attrPre.visible = true;
            preAttrUp = EquipManager.formatAttr(v[1],nextRefineCfg.f_EquipRefineAttribute[k][2])
            attrPreValue.text = "+".. preAttrUp;
        else
            attrPre.visible = false;
        end
    end
    for i = #baseAttrData+1,#tabAttr do
        tabAttr[i].visible = false
    end
end
function UIEquipRefine._formatPercentAttr(attrType, attrValue)
    if attrType == 2 then
        return string.format("%s%%", tostring(attrValue / 100));
    else
        return attrValue;
    end
end
--初始素材列表
function UIEquipRefine.updataEquip()
    itemList = {}
    chooseData = {};
    itemNums = {}
    logicMgr.ItemManager.getItemDatabyItemType( EnumConst.ItemTypeEnum.Refine,itemList);
    logicMgr.ItemManager.getItemDatabyItemType( EnumConst.ItemTypeEnum.EquipStepstone,itemList);
    logicMgr.EquipManager.getEquipList(itemList)
    table.sort(itemList, RedDotsRefineHandler.sort)
    itemTable = {}
    dynamicList.itemRenderer = this.setData;
    dynamicList.numItems = #itemList;
    if #itemList <= 0 then
        nothingController.selectedIndex = 1;
    else
        nothingController.selectedIndex = 0;
    end
end

--初始化物品信息
function UIEquipRefine.setData(idx, itemobj)
    local itemValue = itemList[idx + 1];
    local go = itemobj;
    local item = CtrlManager.GetCtrl(PanelNames.Item);
    if item ~= nil then
        item.initData(go, itemValue); --状态需要全部重置UIMythicDungons
        go.name = itemValue.itemId;
        if this.chooseData[go.name] and go.name == this.chooseData[go.name].itemId then
            local numText = chooseData[go.name].Num .. "/" .. getNumString(itemNums[chooseData[go.name].itemId]);
            item.setNum(go, numText);
            item.setSelectChooseState(go, true, true)
        else
            item.setSelectChooseState(go, false, false);
        end
    end
    go.onClick:Clear();
    go.onClick:Add(function()
        this.onClickItem(go, itemValue);
    end);
    --table.insert(itemTable, go);
end

function UIEquipRefine.onClickItem(go, data)
    local modelId = curEquipData.itemModelId
    local max = logicMgr.EquipManager.GetMaxRefineLevel(modelId)
    if curEquipData.curRfLevel == max then
        UISysTips.AddMsg(getLanguage("ErrorCode_804"))--精炼等级最大了
        return
    end
    --选中
    local item = CtrlManager.GetCtrl(PanelNames.Item);
    local key = data["itemId"];
    local numText = 0;

    if chooseData[key] == nil then
        if curEquipData.curRfLevel + offset == max then
            return ;
        end
        chooseData[key] = data;
        if itemNums[key] == nil then
            itemNums[key] = tonumber(data["num"]);
        end
        item.setSelectChooseState(go, true, true);
        --local consumeExp = curEquipData["consumeExp"];
        local curRfLevel = curEquipData["curRfLevel"];
        local itemAllExp = curEquipData["exp"];
        local refineCfg = dataTable.getDataTableByMultiId("t_equiprefine",data.itemModelId,data.curRfLevel)
        local expMax = this.GetNextMaxExp(modelId,curRfLevel+offset)
        local itemExp;
        if data.tabType == EnumConst.ItemTableEnum.Equip then
            itemExp = data["exp"] + refineCfg.f_EquipBaseExp
        else
            local exp = decodeJsonStrToTabel(data["itemFunction"]);
            itemExp = exp[2];
        end
        local num = math.ceil((expMax - itemAllExp)/itemExp);
        chooseData[key].Num = num < tonumber(chooseData[key].num) and num or chooseData[key].num;
        numText = chooseData[key].Num .. "/" .. getNumString(itemNums[key]);
        item.setNum(go, numText);
    else
        chooseData[key].Num = chooseData[key].Num - 1;
        if chooseData[key].Num == 0 then
            chooseData[key].Num = itemNums[key];
            item.setSelectChooseState(go, false, false);
            item.setNum(go, itemNums[key]);
            chooseData[key] = nil;
            itemNums[key] = nil;
        else
            numText = chooseData[key].Num .. "/" .. getNumString(itemNums[key]);
            item.setNum(go, numText);
        end
    end
    this.upRefineLevel();
    this.updataEquipAttr();
    this.updataBtnRefineState();
    this.oneKeySelectLevel = curEquipData.curRfLevel + offset
    this.enter_flag = false
end
function UIEquipRefine.GetNextMaxExp(id,refineLevel)
    local cfg = dataTable.getDataTableByMultiId("t_equiprefine",id,refineLevel)
    if not cfg then
        logError("找不到t_equiprefine "..id..",lv:"..refineLevel)
        return 0
    end
    return cfg.f_EquipRefineLevelExp
end
function UIEquipRefine.GetNeedTotalExp(id,curLevel,nextRefineLevel)
    if nextRefineLevel <= curLevel then
        return 0
    end
    local exp = 0
    while(curLevel < nextRefineLevel) do
        exp = exp + this.GetNextMaxExp(id,curLevel)
        curLevel = curLevel + 1
    end
    return exp
end
function UIEquipRefine.updataBtnRefineState()
    local count = 0;
    for k, v in pairs(chooseData) do
        count = count + 1;
    end
    if chooseData ~= nil and count >= 1 then
        btn_refine:GetController("gray").selectedIndex = 0;
        btn_refine.touchable = true
        btn_refine.enabled = true
    else
        btn_refine:GetController("gray").selectedIndex = 1;
        btn_refine.touchable = false
        btn_refine.enabled = false
    end
end

--确认精炼，sentMsg
function UIEquipRefine.onClickRefine()
    local isTip,tip2 = nil,nil
    local money = logicMgr.ItemManager.getCurrencyCountByModelId(CurrencyEnum.MONEY);
    if money < itemAllCost then
        UISysTips.AddMsg(string.format(getLanguage("Character_Tips19"),ItemManager.GetItemName(CurrencyEnum.MONEY)));
        AudioManager.Play(2010)
        return ;
    end
    local max = logicMgr.EquipManager.GetMaxRefineLevel(curEquipData.itemModelId)
    if curEquipData.curRfLevel == max then
        UISysTips.AddMsg(getLanguage("ErrorCode_804"))--精炼等级最大了
        AudioManager.Play(2010)
        return
    end
    local refineTable = {};
    for k, v in pairs(chooseData) do
        if logicMgr.ItemManager.IsEquip(v.itemModelId) then
            if v.quality > curEquipData.quality then
                isTip = true
            end

            if v.quality >= 8 then
                tip2 = true
            end
        elseif v.itemType == EnumConst.ItemTableEnum.EquipBroken then
            if v.quality >= 8 then
                tip2 = true
            end
        end
        local costItemInfo = CostItemInfo.New();
        costItemInfo["itemId"] = v.itemId;
        costItemInfo["itemModelId"] = v.itemModelId;
        costItemInfo["itemNum"] = v.Num;
        table.insert(refineTable, costItemInfo)
    end
    if #refineTable == 0 then
        return
    end
    if isTip or tip2 then
        local popid = tip2 and 128 or 91
        local pop = CtrlManager.GetCtrl(PanelNames.UICommonPop);
        pop.Init(tostring(popid), function(b)
            if b then
                equipHandler.sendRefine(curShowHeroData.partnerId, partID, refineTable)
                this.updataEquip();
                itemNums = {}
                chooseData = {}
            end
        end)
    else
        equipHandler.sendRefine(curShowHeroData.partnerId, partID, refineTable)
        this.updataEquip();
        itemNums = {}
        chooseData = {}
    end
end
function UIEquipRefine.ClickHelp()
    local txts = {};
    txts["title"] = "HelpTitle46"
    txts["des"] = "HelpDes46"
    txts["story"] = "FunctionStory402"
    showUI(PanelNames.CommonTips, txts);
end
function UIEquipRefine.ResetChooseData()
    chooseData = {}
    itemNums = {}
    dynamicList.numItems = #itemList;
end
--一键选择
function UIEquipRefine.onClickChoose()
    local modelId = curEquipData.itemModelId
    local max = logicMgr.EquipManager.GetMaxRefineLevel(modelId)
    if curEquipData.curRfLevel == max then
        UISysTips.AddMsg(getLanguage("ErrorCode_804"))--精炼等级最大了
        return
    end
    local curRfLevel = curEquipData["curRfLevel"];

    if this.oneKeySelectLevel == 0 then
        this.oneKeySelectLevel = curRfLevel + 1;
    else
        if not this.enter_flag then
            this.oneKeySelectLevel = this.oneKeySelectLevel + 1
        end
    end

    if this.oneKeySelectLevel > max then
        UISysTips.AddMsg(getLanguage("EquipRefineTips1"))--材料足够，并已达到可强化的最高级
        return
    end

    if #itemList == 0 then
        UISysTips.AddMsg(getLanguage("EquipRefineTips3"))--没有材料
        return
    end

    this.ResetChooseData()
    this.oneKeySelectLevel = math.min(this.oneKeySelectLevel,max)
    --local consumeExp = curEquipData["consumeExp"];

    local itemAllExp = curEquipData["exp"];
    local expMax = this.GetNeedTotalExp(modelId,curRfLevel,this.oneKeySelectLevel)--consumeExp[curRfLevel + 1];
    local itemExp;

    for i = 1, #itemList do
        if expMax - itemAllExp <= 0 then
            break;
        end
        local data = itemList[i]
        itemExp = 0;
        local refineCfg = dataTable.getDataTableByMultiId("t_equiprefine",data.itemModelId,data.curRfLevel)
        if data.tabType == EnumConst.ItemTableEnum.Equip then
            itemExp = data.exp + refineCfg.f_EquipBaseExp
        else
            local exp = decodeJsonStrToTabel(data["itemFunction"]);
            itemExp = exp[2];
        end
        local num = math.ceil((expMax - itemAllExp) / itemExp);
        if num > 0 then
            chooseData[data.itemId] = data;
            chooseData[data.itemId].Num = num < tonumber(chooseData[data.itemId].num) and num or chooseData[data.itemId].num;
            itemAllExp = itemAllExp+chooseData[data.itemId].Num*itemExp;
            itemNums[data.itemId] = data.num;

            if chooseData[data.itemId].Num == data.num then
                chooseData[data.itemId].all = true
            end
        end
    end
    dynamicList.numItems = #itemList;
    --local ctrlItem = CtrlManager.GetCtrl(PanelNames.Item)
    --for k, v in pairs(itemTable) do
    --    if chooseData[v.name] and v.name == chooseData[v.name].itemId then
    --        local numText = chooseData[v.name].Num .. "/" .. getNumString(itemNums[chooseData[v.name].itemId ]);
    --        ctrlItem.setNum(v, numText);
    --        ctrlItem.setSelectChooseState(v, true, true)
    --    end
    --end

    if itemAllExp < expMax then
        if not this.enter_flag then --材料不足提示处理
            this.enter_flag = true

            local select_all = true
            for k,v in pairs(chooseData) do
                if not v.all then
                    select_all = false
                    break
                end
            end
            if select_all then
                UISysTips.AddMsg(getLanguage("EquipRefineTips2"))--材料不够
            end
        else
            UISysTips.AddMsg(getLanguage("EquipRefineTips2"))--材料不够
        end
        --logError("所选材料不足>>>>>>>>>>>>>>>")
    end

    this.upRefineLevel();
    this.updataEquipAttr();
    this.updataBtnRefineState();
end

--取消一键选择
function UIEquipRefine.onClickCancel()
    --local ctrlItem = CtrlManager.GetCtrl(PanelNames.Item)
    --for k, v in pairs(itemTable) do
    --    if chooseData[v.name] ~= nil and v.name == chooseData[v.name].itemId then
    --        local numText = chooseData[v.name].num;
    --        ctrlItem.setNum(v, numText);
    --        ctrlItem.setSelectChooseState(v, false, false)
    --    end
    --end
    dynamicList.numItems = #itemList;
    chooseData = {};
    itemNums = {};
    this.enter_flag = false
    this.upRefineLevel();
    this.updataEquipAttr();
    this.updataBtnRefineState();
    this.updataEquip();
end

function UIEquipRefine.upRefineLevel()
    itemAllCost = 0;
    local itemModelId = curEquipData.itemModelId
    local refineCfg = dataTable.getDataTableByMultiId("t_equiprefine", itemModelId, curEquipData.curRfLevel)
    if not refineCfg then
        logError("找不到t_equiprefine ".. itemModelId ..",level:"..curEquipData.curRfLevel)
        return
    end
    --local consumeExp = curEquipData["consumeExp"];
    local refineMaxlv = logicMgr.EquipManager.GetMaxRefineLevel(itemModelId);
    local curRfLevel = curEquipData["curRfLevel"];
    local itemAllExp = curEquipData["exp"];
    --local expMax = consumeExp[curRfLevel + 1];
    local expLevel = 0;
    if chooseData ~= nil and table.getn(chooseData) then
        for k, v in pairs(chooseData) do
            local itemExp = 0;
            if v.tabType == EnumConst.ItemTableEnum.Equip then
                local cfg = dataTable.getDataTableByMultiId("t_equiprefine",v.itemModelId,v.curRfLevel)
                if cfg then
                    itemExp = itemExp + cfg.f_EquipBaseExp
                else
                    logError("找不到refineCfg "..v.itemModelId..",lv:"..v.curRfLevel)
                end
                --[[if tonumber(v.curRfLevel) == 0 then
                    itemExp = v["baseExp"] + v["exp"];
                else
                    itemExp = v["baseExp"];
                    for i = 1, tonumber(v["curRfLevel"]) do
                        itemExp = itemExp + consumeExp[i];
                    end
                    itemExp = itemExp + v["exp"];
                end]]
            else
                local exp = v["itemFunction"]
                itemExp = exp[2]
            end
            itemAllExp = itemAllExp + itemExp * v.Num;
            itemAllCost = itemAllCost + itemExp * v.Num * refineCfg.f_EquipRefineGoldCo;
        end

        for i = curRfLevel, refineMaxlv do
            local cfg = dataTable.getDataTableByMultiId("t_equiprefine", itemModelId,i)
            if itemAllExp >= cfg.f_EquipRefineLevelExp then
                --if curRfLevel + 1 == refineMaxlv then
                --    offset = 1;
                --    expLevel = offset;
                --else
                if i + 1 == refineMaxlv then
                    offset = i + 1 - curRfLevel;
                    expLevel = offset - 1;
                    break;
                else
                    itemAllExp = itemAllExp - cfg.f_EquipRefineLevelExp;
                end
                --end
            else
                offset = i - curRfLevel;
                expLevel = offset;
                break ;
            end
        end
        if offset > 0 then
            up.visible = true;
            upnum.text = curRfLevel+offset;
        else
            up.visible = false;
        end
    else
        up.visible = false;
        offset = 0;
    end
    local cfg = dataTable.getDataTableByMultiId("t_equiprefine", itemModelId,curRfLevel + math.max(expLevel,0))
    local expMax = cfg.f_EquipRefineLevelExp
    --expMax = consumeExp[curRfLevel + 1 + expLevel];
    slider.value = itemAllExp*100 / expMax;
    sliderNum.text = itemAllExp .. "/" .. expMax;
    if itemAllExp > expMax and itemAllCost > (itemAllExp - expMax) * refineCfg.f_EquipRefineGoldCo then
        itemAllCost = itemAllCost - (itemAllExp - expMax) * refineCfg.f_EquipRefineGoldCo;
    end
    level.text = curEquipData["curRfLevel"];
    local money = logicMgr.ItemManager.getCurrencyCountByModelId(CurrencyEnum.MONEY);
    if itemAllCost > money then
        money = string.TextColor(getNumString(money),"#FF0000")
    else
        money = getNumString(money)
    end
    -- local text = money.."/"..getNumString(itemAllCost) ;
    local text = getNumString(itemAllCost) .. "/" .. money
    num.text = text
end

--function UIEquipRefine.sort(a, b)
--    --装备【品质（从低到高）→部位（1到4）
--    if a.itemType > b.itemType then
--        return true;
--    elseif a.itemType == b.itemType then
--        if a.itemType == EnumConst.ItemTypeEnum.Equip then
--            if (a.quality < b.quality) then
--                return true;
--            elseif (a.quality == b.quality) then
--                if a.part < b.part then
--                    return true;
--                else
--                    return false;
--                end
--            else
--                return false;
--            end
--        elseif a.itemType == EnumConst.ItemTypeEnum.Refine then
--            if a.itemModelId < b.itemModelId then
--                return true;
--            else
--                return false;
--            end
--        end
--    else
--        return false;
--    end
--end

function UIEquipRefine.onClickClose()
    closeUI(PanelNames.UIEquipRefine);
end

return UIEquipRefine;